package com.liuya.safe.policy.controller;

import com.liuya.common.I18N;
import com.liuya.safe.controller.AbstractTreeContrller;
import com.liuya.safe.tree.AbstractTreeHandler;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * 查询策略管理树
 * @author liuya
 * @date 20160826
 */
@Controller
@Api(value = "查询策略管理树", description = "查询策略管理树")
@RequestMapping(value = "queryMng")
public class QueryManagerContrller extends AbstractTreeContrller {

    @Autowired
    public void setTreeHandler(@Qualifier("queryTreeHandler") AbstractTreeHandler treeHandler) {
        this.treeHandler = treeHandler;
    }

    // 查询会话
    @ApiOperation(value = "查询会话")
//    @RequiresPermissions("sys.queryMng.openTree")
    @RequestMapping(value = "/openTree")
    public String openTree(HttpServletRequest request, ModelMap modelMap){
        System.out.println(request.getSession().getId());
        return super.openTree(request, modelMap);
    }

    @ApiOperation(value = "加载树内容")
//    @RequiresPermissions("sys.queryMng.loadTree")
    @RequestMapping(value = "/loadTree", produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public Object loadTree(HttpServletRequest request, ModelMap modelMap){
        return super.loadTree(request, modelMap);
    }

    @ApiOperation(value = "加载树内容")
//    @RequiresPermissions("sys.queryMng.menu")
    @RequestMapping(value = "/menu")
    public String menu(HttpServletRequest request, ModelMap modelMap){
        return super.menu(request, modelMap);
    }

    @ApiOperation(value = "创建一个节点")
//    @RequiresPermissions("sys.queryMng.create")
    @RequestMapping(value = "/preCreate")
    public Object preCreate(HttpServletRequest request, ModelMap modelMap){
        return treeHandler.getCreatePage();
    }

    @ApiOperation(value = "添加新创建的节点")
//    @RequiresPermissions("sys.queryMng.add")
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(HttpServletRequest request, ModelMap modelMap) {
        boolean result = (boolean) super.add(request, modelMap);
        if(result)
            return I18N.getInstance().say("AddSuccess");
        else
            return I18N.getInstance().say("AddFail");
    }

    @ApiOperation(value = "复制一个节点")
//    @RequiresPermissions("sys.queryMng.copyPage")
    @RequestMapping(value = "/preCopy")
    public Object preCopy(HttpServletRequest request, ModelMap modelMap){
        return super.preCopy(request, modelMap);
    }

    @ApiOperation(value = "执行复制一个节点")
//    @RequiresPermissions("sys.queryMng.copyNode")
    @RequestMapping(value = "/copy")
    @ResponseBody
    public Object copy(HttpServletRequest request, ModelMap modelMap){
        boolean result = (boolean) super.copy(request, modelMap);
        if(result)
            return I18N.getInstance().say("CopySuccess");
        else
            return I18N.getInstance().say("CopyFail");
    }

    @ApiOperation(value = "修改一个节点")
//    @RequiresPermissions("sys.queryMng.modify")
    @RequestMapping(value = "/preModify")
    public Object preModify(HttpServletRequest request, ModelMap modelMap){
        return super.preModify(request, modelMap);
    }

    @ApiOperation(value = "验证节点名称")
//    @RequiresPermissions("sys.queryMng.nameValid")
    @RequestMapping(value = "/isNameValid", produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public Object isNameValid(HttpServletRequest request, ModelMap modelMap){
        return super.isNameValid(request, modelMap);
    }

    @ApiOperation(value = "删除一个节点")
//    @RequiresPermissions("sys.queryMng.delete")
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(HttpServletRequest request, ModelMap modelMap){
        boolean result = (boolean) super.delete(request, modelMap);
        if(result)
            return I18N.getInstance().say("DeleteSuccess");
        else
            return I18N.getInstance().say("DeleteFail");
    }

    @ApiOperation(value = "更新一个节点")
//    @RequiresPermissions("sys.queryMng.update")
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(HttpServletRequest request, ModelMap modelMap){
        return super.update(request, modelMap);
    }

    @ApiOperation(value = "移动一个节点")
//    @RequiresPermissions("sys.queryMng.move")
    @RequestMapping(value = "/move")
    @ResponseBody
    public Object move(HttpServletRequest request, ModelMap modelMap){
        return super.move(request, modelMap);
    }

}
